<template>
	<view class="statisticsBox">
		<view class="navBox">
			<u-navbar title="统计详情" :autoBack="true" :titleStyle="{fontWeight:'900'}" bgColor="#ffffff">
			</u-navbar>
		</view>
		<view class="topBox" :style="'top:'+(customBarHeight*2)+'rpx;'">
			<image src="../../static/images/scanRecordBg.png" class="recordBg"></image>
			<view class="school">参与学校：{{school_name }}</view>
			<view class="title">各体验项目参与情况：</view>
		</view>
		<viiew class="statisticsDataBox" :style="'top:'+(190+(customBarHeight*2))+'rpx;'">
			<view class="statisticsData">
				<image src="../../static/images/mine_options.png" class="statisticsBg"></image>
				<view class="dataItem">
					<view class="label">扫码项目</view>
					<view class="value">{{statisticsList.length}}</view>
				</view>
				<view class="dataItem">
					<view class="label">扫码总次数</view>
					<view class="value">{{scanTotalSum}}</view>
				</view>
			</view>
		</viiew>
		<scroll-view scroll-y="true" class="scroll-Y statisticsListBox"
			:style="'height:'+(pageHeight-(170+customBarHeight))+'px;top:'+(340+(customBarHeight*2))+'rpx;'">
			<view class="statisticsList " v-if="statisticsList.length>0">
				<view class="statisticsItem" v-for="(item,index) in statisticsList" :key="index">
					<view class="name">{{item.project_name}}</view>
					<view class="value">
						已参与扫码
						<text class="number">{{item.scan_sum}}</text>
						次
					</view>
				</view>
			</view>
			<view class="noData" v-else>
				<image src="../../static/images/nodata.png" class="image"></image>
				<view class="text">暂时还没有统计数据哦～</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	const app = getApp();
	import {
		statisticsDetail
	} from "@/api/api.js"
	export default {
		data() {
			return {
				school_name: '',
				experience_id: null,
				school_id: null,
				statisticsList: [], //统计数据列表
				customBarHeight: Number(44 + app.globalData.statusBar),
				pageHeight: 0,
			}
		},
		computed: {
			scanTotalSum() {
				let scanTotalSum = 0
				this.statisticsList.map(item => {
					scanTotalSum += item.scan_sum
				})
				return scanTotalSum
			}
		},
		onLoad(options) {
			let that = this
			uni.getSystemInfo({
				success(res) {
					that.pageHeight = Number(res.windowHeight)
				}
			})
			if (options && options.school_name) {
				this.school_name = options.school_name
				this.school_id = options.school_id
				this.experience_id = options.experience_id
				this.statisticsDetail()
			}
		},
		methods: {
			statisticsDetail() {
				statisticsDetail({
					school_id: this.school_id,
					experience_id: this.experience_id,
				}).then(res => {
					this.statisticsList = res.data
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fillBox {
		width: 100%;
		height: 108rpx;
		background: #f8f8f8;
	}

	.noData {
		padding-top: 100rpx;
		margin: 0 auto;
		text-align: center;

		.image {
			width: 320rpx;
			height: 320rpx;
		}

		.text {
			font-size: 28rpx;
			color: #B0B0B0;
		}
	}

	.statisticsBox {
		min-height: 100vh;
		background-color: #f8f8f8;
	}

	.navBox {
		position: relative;
		z-index: 1000;
	}

	.topBox {
		width: 100%;
		position: fixed;
		top: 160rpx;
		z-index: 100;
		color: #ffffff;

		.recordBg {
			position: fixed;
			width: 100%;
			height: 236rpx;
		}

		.school {
			position: relative;
			font-size: 36rpx;
			margin: 18rpx 34rpx 10rpx;
		}

		.title {
			font-size: 28rpx;
			margin: 0rpx 34rpx 10rpx;
			position: relative;
		}
	}

	.statisticsDataBox {
		width: 100%;
		position: fixed;
		top: 260rpx;
		z-index: 200;

		.statisticsBg {
			position: absolute;
			width: 100%;
			height: 154rpx;
		}

		.statisticsData {
			margin: 0rpx 34rpx 10rpx;
			position: relative;
			z-index: 300;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.dataItem {
				flex: 1;
				position: relative;
				text-align: center;

				.label {
					font-size: 28rpx;
				}

				.value {
					margin-top: 20rpx;
					font-weight: 600;
					font-size: 44rpx;
					color: #49A1FD;
				}
			}
		}
	}

	.statisticsListBox {
		position: relative;

		.statisticsList {
			position: relative;
			z-index: 200;
			padding-bottom: 20rpx;

			.statisticsItem {
				margin: 0rpx 34rpx 10rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 88rpx;
				font-size: 28rpx;
				margin-bottom: 20rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 4rpx 0rpx rgba(0, 0, 0, 0.04);
				border-radius: 20rpx;

				.name,
				.value {
					flex: 1;
					margin: 0 28rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;

				}

				.number {
					color: #49A1FD;
				}
			}
		}
	}
</style>